//
//  SetSeveralHvacTimerApi.m
//  AFNetworking
//
//  Created by Henry on 2023/3/14.
//

#import "SetSeveralHvacTimerApi.h"
@interface SetSeveralHvacTimerApi()

@property(nonatomic,strong)NSMutableArray * timer_list;
@property(nonatomic,strong)NSMutableArray * weeks;

@end
@implementation SetSeveralHvacTimerApi

-(id)initWithDevId:(NSString *)thingName withTemp:(NSMutableArray <TimerModel *>*)timer_list withWeek:(NSMutableArray *)weeks withThingTypeName:(NSString *)thingTypeName{
    if(self = [super init]){
        self.thingName = thingName;
        self.timer_list = timer_list;
        self.weeks =weeks;
        self.thingTypeName = thingTypeName;
    }
    return self;
}


-(id)getTopic{
    return [NSString stringWithFormat:@"$aws/things/%@/shadow/name/%@/update",self.thingName,self.thingTypeName];
}

-(id)getCommandContent{
    
    NSMutableDictionary *dic = [[NSMutableDictionary alloc] init];
    
    NSMutableArray *list_1 = [[NSMutableArray alloc] init];
    
    NSMutableArray *list_2 = [[NSMutableArray alloc] init];
    
    NSMutableArray *list_3 = [[NSMutableArray alloc] init];
    
    NSMutableArray *list_4 = [[NSMutableArray alloc] init];
    
    NSMutableArray *list_5 = [[NSMutableArray alloc] init];
    
    NSMutableArray *list_6 = [[NSMutableArray alloc] init];
    
    NSMutableArray *list_7 = [[NSMutableArray alloc] init];
    
    [self.timer_list enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        TimerModel *model = obj;
        NSString *de = [model.Timer
                        stringByReplacingOccurrencesOfString:@":" withString:@""];
        NSNumber *time = [NSNumber numberWithInt:[de intValue]];
            NSDictionary *dic=@{@"Timer":time,@"Mode":model.Mode};
        [list_1 addObject:dic];
        [list_2 addObject:dic];
        [list_3 addObject:dic];
        [list_4 addObject:dic];
        [list_5 addObject:dic];
        [list_6 addObject:dic];
        [list_7 addObject:dic];
          
    }];
    
    if([self.weeks containsObject:@1]){
        [dic addEntriesFromDictionary:@{@"Monday":list_1}];
    }
    if([self.weeks containsObject:@2]){
        [dic addEntriesFromDictionary:@{@"Tuesday":list_2}];
    }
    if([self.weeks containsObject:@3]){
        [dic addEntriesFromDictionary:@{@"Wednesday":list_3}];
    }
    if([self.weeks containsObject:@4]){
        [dic addEntriesFromDictionary:@{@"Thursday":list_4}];
    }
    if([self.weeks containsObject:@5]){
        [dic addEntriesFromDictionary:@{@"Friday":list_5}];
    }
    if([self.weeks containsObject:@6]){
        [dic addEntriesFromDictionary:@{@"Saturday":list_6}];
    }
    if([self.weeks containsObject:@7]){
        [dic addEntriesFromDictionary:@{@"Sunday":list_7}];
    }
    
    
    
    return @{@"state":@{@"desired":@{@"DevConfig":@{@"TimerTask":dic}}}};
}

-(id)getSubcribeTopic{
    return [NSString stringWithFormat:@"$aws/things/%@/shadow/name/%@/update/accepted",self.thingName,self.thingTypeName];
}
@end
